package ar.edu.itba.it.cg.grupo01.impl.shape;

import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import ar.edu.itba.it.cg.grupo01.api.Intersection;
import ar.edu.itba.it.cg.grupo01.api.Ray;
import ar.edu.itba.it.cg.grupo01.api.shape.Shape;
import ar.edu.itba.it.cg.grupo01.impl.IntersectionFactory;

public class CompositeShape extends AbstractShape {

	private Set<Shape> members;
	
	public CompositeShape(Collection<? extends Shape> members,
			IntersectionFactory intersectionFactory) {
		super(intersectionFactory);
		this.members = new HashSet<Shape>(members);
	}

	@Override
	public Intersection<? extends Shape> intersects(Ray ray) {
		
		Set<Intersection<? extends Shape>> intersections = new HashSet<Intersection<? extends Shape>>();
		for (Shape shape : members) {
			intersections.add(shape.intersects(ray));
		}
		
		return intersectionFactory.createIntersection(intersections);
	}

}
